package ru.isys.view;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ru.isys.xml.XmlItem;

public class BindItem extends JPanel {
    
    private String item;
    private String fullName;
	private JTextField nodeSetField;
	private JTextField typeField;
	private JTextField constraint;
	private JComboBox required;
	private JComboBox readonly;
	private int level;

	private BindItem() {

	}

	public BindItem(String item,String fullName, int level) {
		this.item=item;
	    setSize(450, 25);
		setBackground(Color.GRAY);
		setBorder(BorderFactory.createLineBorder(Color.BLACK));
		setBounds(level * 10, 5, 850, 45);

		add(new JLabel("nodeSet = "));
		nodeSetField = new JTextField();
		nodeSetField.setColumns(20);
		nodeSetField.setText(fullName);
		add(nodeSetField);

		add(new JLabel("type = "));
		typeField = new JTextField();
		typeField.setColumns(10);
		add(typeField);

		add(new JLabel("constraint = "));
		constraint = new JTextField();
		constraint.setColumns(10);
		add(constraint);

		add(new JLabel("required"));
		required = new JComboBox();
		required.addItem(Boolean.FALSE);
		required.addItem(Boolean.TRUE);
		add(required);

		add(new JLabel("readonly"));
		readonly = new JComboBox();
		readonly.addItem(Boolean.FALSE);
		readonly.addItem(Boolean.TRUE);
		add(readonly);

		this.level = level;

	}

	public int getLevel() {
		return level;
	}

	public String getNodeSetField() {
		return nodeSetField.getText();
	}

	public void setNodeSetField(String nodeSetFieldText) {
		this.nodeSetField.setText(nodeSetFieldText);
	}

	public String getTypeField() {
		return typeField.getText();
	}

	public void setTypeField(String typeFieldText) {
		this.typeField.setText(typeFieldText);
	}

	public String getConstraint() {
		return constraint.getText();
	}

	public void setConstraint(String constraintText) {
		this.constraint.setText(constraintText);
	}

	public boolean getReadonly() {
		if (readonly.getSelectedIndex() == 1) {
			return true;
		} else {
			return false;
		}
	}
	
	public boolean getRequired() {
		if (required.getSelectedIndex() == 1) {
			return true;
		} else {
			return false;
		}
	}

    public String getItem()
    {        
        return item;
    }

    public void setItem(String item)
    {        
        this.item = item;
    }
}
